package worker.model.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import worker.model.dao.SpcDao;
import worker.model.vo.MemberVO;
import worker.model.vo.StaticsVO;

public class SpcService {
	private SpcDao spcDao;

	public void setSpcDao(SpcDao spcDao) {
		this.spcDao = spcDao;
	}
	/**
	 * 120526 조철희
	 * 로그인
	 */
	public Object login(MemberVO mvo) {
		Object obj = null;
		try {
			obj = spcDao.login(mvo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return obj;
	}
	/**
	 * 120527 조철희
	 * SPC 메뉴 첫화면
	 * SPC 메뉴 접속시 다양한 종류의 통계를 보여줌 (총 20개 데이터)
	 * EveryDay 와 Today 를 기준으로 WorkOrder 현황, Quantity 현황, Operation 별 Defect 현황
	 */
	public HashMap getSpcInfoStatics() {
		HashMap map = new HashMap();
		try {
/*1*/	map.put("ES1Fail", spcDao.getES1Fail());							map.put("ES2Fail", spcDao.getES2Fail());							map.put("ES3Fail", spcDao.getES3Fail());						map.put("ES4Fail", spcDao.getES4Fail());
/*2*/	map.put("TS1Fail", spcDao.getTS1Fail());							map.put("TS2Fail", spcDao.getTS2Fail());							map.put("TS3Fail", spcDao.getTS3Fail());						map.put("TS4Fail", spcDao.getTS4Fail());
/*3*/map.put("OneAgoS4Ok", spcDao.getOneAgoS4Ok());		map.put("TwoAgoS4Ok", spcDao.getTwoAgoS4Ok());		map.put("ThrAgoS4Ok", spcDao.getThrAgoS4Ok());	map.put("FouAgoS4Ok", spcDao.getFouAgoS4Ok());	
/*4*/map.put("FivAgoS4Ok", spcDao.getFivAgoS4Ok());			map.put("SixAgoS4Ok", spcDao.getSixAgoS4Ok());		map.put("SevAgoS4Ok", spcDao.getSevAgoS4Ok());	
/*5*/	map.put("OneAgoSTfail", spcDao.getOneAgoSTfail());	map.put("TwoAgoSTfail", spcDao.getTwoAgoSTfail());	map.put("ThrAgoSTfail", spcDao.getThrAgoSTfail());	map.put("FouAgoSTfail", spcDao.getFouAgoSTfail());
/*6*/	map.put("FivAgoSTfail", spcDao.getFivAgoSTfail());		map.put("SixAgoSTfail", spcDao.getSixAgoSTfail());	map.put("SevAgoSTfail", spcDao.getSevAgoSTfail());
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		return map;
	}
	/**
	 * 120529 조철희
	 * FMB 메뉴 첫화면
	 * FMB 메뉴 접속시 다양한 종류의 통계를 보여줌 (총 38개 데이터)
	 * Dash Board(오늘 생산량, 오늘 접수량에 따른 진행양, 총일 생산량, 접수량..)
	 */
	public HashMap getFmbInfoStatics() {
		HashMap map = new HashMap();
		try {
/*1*/	map.put("EOTotal", spcDao.getEOTotal());							map.put("EOOk", spcDao.getEOOk());								map.put("EONo", spcDao.getEONo());							map.put("EQTotal", spcDao.getEQTotal());
/*2*/	map.put("EQOk", spcDao.getEQOk());map.put("EQNo", (Integer) spcDao.getEQTotal() - (Integer) spcDao.getEQOk());map.put("TOTotal", spcDao.getTOTotal());			map.put("TOOk", spcDao.getTOOk());
/*3*/	map.put("TONo", spcDao.getTONo());								map.put("TQTotal", spcDao.getTQTotal());						map.put("TQOk", (Integer)spcDao.getTQOk());							map.put("TQNo", (Integer) spcDao.getTQTotal() -(Integer)spcDao.getTQOk());
/*4*/	map.put("ES1Total", spcDao.getES1Total());						map.put("ES1Ok", spcDao.getES1Ok());								map.put("ES1Fail", spcDao.getES1Fail());						map.put("ES2Total", spcDao.getES2Total());
/*5*/	map.put("ES2Ok", spcDao.getES2Ok());							map.put("ES2Fail", spcDao.getES2Fail());							map.put("ES3Total", spcDao.getES3Total());					map.put("ES3Ok", spcDao.getES3Ok());
/*6*/	map.put("ES3Fail", spcDao.getES3Fail());							map.put("ES4Total", spcDao.getES4Total());						map.put("ES4Ok", spcDao.getES4Ok());						map.put("ES4Fail", spcDao.getES4Fail());
/*7*/	map.put("TS1Total", spcDao.getTS1Total());						map.put("TS1Ok", spcDao.getTS1Ok());								map.put("TS1Fail", spcDao.getTS1Fail());						map.put("TS2Total", spcDao.getTS2Total());
/*8*/	map.put("TS2Ok", spcDao.getTS2Ok());							map.put("TS2Fail", spcDao.getTS2Fail());							map.put("TS3Total", spcDao.getTS3Total());					map.put("TS3Ok", spcDao.getTS3Ok());
/*9*/	map.put("TS3Fail", spcDao.getTS3Fail());							map.put("TS4Total", spcDao.getTS4Total());						map.put("TS4Ok", spcDao.getTS4Ok());						map.put("TS4Fail", spcDao.getTS4Fail());
/*10*/map.put("RealTQOk",spcDao.getRealTQOk());					map.put("RealTQNo",spcDao.getRealTQNo());
		} catch (SQLException e) {
			e.printStackTrace(); 
		}	
		return map;
	}
	/**
	 * 이주연 추가: 날짜별 성공, 실패 수량 조회
	 * @return
	 */
	public ArrayList<StaticsVO> getDayOfPassAndFailQuantity() {
		ArrayList<StaticsVO> list= null;
		try {
			list= this.spcDao.getDayOfPassAndFailQuantity();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 120601 조철희
	 * 전날 생산량, 불량품량 DB 저장 (Statics)
	 */
	public String statics(HashMap map) {
		String flag="Y";
		try {
			spcDao.statics(map);
		} catch (SQLException e) {
			flag = "N";
		}
		return flag;
	}
}
